//
//  XJSureOrderFailView.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/6/23.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJSureOrderFailView.h"
@interface XJSureOrderFailView()
@property(nonatomic, strong) UIView *bgView; //1.背景
@property(nonatomic, strong) UIImageView *errorTipsIv; //2.错误提示图片
@property(nonatomic, strong) UILabel *errorTipsLb; //错误提示lb
@property(nonatomic, strong) UIButton *retryButton; //重试按钮


@end

@implementation XJSureOrderFailView
#pragma mark - 一 lazy
- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [UIView new];
        //不加颜色就是透明的。
        _bgView.backgroundColor = [UIColor whiteColor];
    }
    return _bgView;
}
- (UIImageView *)errorTipsIv {
    if (!_errorTipsIv) {
        _errorTipsIv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tip_net"]];
    }
    return _errorTipsIv;
}

- (UILabel *)errorTipsLb {
    if (!_errorTipsLb) {
        _errorTipsLb = [UILabel new];
        _errorTipsLb.text = @"网络连接失败";
        _errorTipsLb.textAlignment = NSTextAlignmentCenter;
        _errorTipsLb.textColor = [UIColor lightGrayColor];
    }
    return _errorTipsLb;
}
- (UIButton *)retryButton {
    if (!_retryButton) {
        _retryButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_retryButton setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
        [_retryButton setTitleColor:[UIColor lightGrayColor] forState:(UIControlStateHighlighted)];
        [_retryButton setTitle:@"重试" forState:(UIControlStateNormal)];

        _retryButton.backgroundColor = XJCOLOR_RGB(255, 218, 67);
        _retryButton.layer.masksToBounds = YES;
        _retryButton.layer.cornerRadius = 10;
        
        [_retryButton addTarget:self action:@selector(retryButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _retryButton;
}

#pragma mark - 二 init
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}

- (void)setupView {
    [self addSubview:self.bgView];
    [self.bgView addSubview:self.errorTipsIv];
    [self.bgView addSubview:self.errorTipsLb];
    [self.bgView addSubview:self.retryButton];
}

#pragma mark - 三 布局
- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    [self.errorTipsIv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgView.mas_top).offset(100);
        make.centerX.equalTo(self.bgView.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(150, 150));
    }];
    [self.errorTipsLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.errorTipsIv.mas_bottom).offset(20);
        make.centerX.equalTo(self.bgView.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(150, 30));
    }];
    
    [self.retryButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.errorTipsLb.mas_bottom).offset(20);
        make.centerX.equalTo(self.bgView.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(100, 40));
    }];
}
#pragma mark - 四 回调事件
- (void)retryButtonAction:(UIButton *)button {
    
    if ([self.delegate respondsToSelector:@selector(sureOrderFailViewRetryAction)]) {
        [self.delegate sureOrderFailViewRetryAction];
    }
}

@end
